package net.shopxx.dao.impl;

import java.util.List;

import net.shopxx.dao.GoodsDao;
import net.shopxx.entity.Goods;

import org.springframework.stereotype.Repository;

/**
 * Dao实现类 - 退货
 * ============================================================================
 * 版权所有 2008-2010 长沙鼎诚软件有限公司，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 提示：在未取得SHOP++商业授权之前，您不能将本软件应用于商业用途，否则SHOP++将保留追究的权力。
 * ----------------------------------------------------------------------------
 * 官方网站：http://www.shopxx.net
 * ----------------------------------------------------------------------------
 * KEY: SHOPXX6624D83301C073E40676B792A192D5EE
 * ============================================================================
 */

@Repository
public class GoodsDaoImpl extends BaseDaoImpl<Goods, String> implements GoodsDao {
	
	@SuppressWarnings("unchecked")
	public String getLastGoodsSn() {
		String hql = "from Goods as goods order by goods.createDate desc";
		List<Goods> goodsList =  getSession().createQuery(hql).setFirstResult(0).setMaxResults(1).list();
		if (goodsList != null && goodsList.size() > 0) {
			return goodsList.get(0).getGoodsSn();
		} else {
			return null;
		}
	}

	@Override
	public boolean checkGoodsSn(String goodSn) {
	    String str = "from Goods as goods where lower(goods.goodsSn) = lower(:goodsSn)";
	    Goods localGoods = (Goods)getSession().createQuery(str).setParameter("goodsSn", goodSn).uniqueResult();
	    return localGoods != null;
	}

}